package com.yunda.vedioutils;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.yunda.vedio_library.PlayAudioActivity;
import com.yunda.vedio_library.SimplePlayer;
import com.yunda.vedio_library.imp.CompressListener;
import com.yunda.vedio_library.util.Utils;
import com.yunda.vedio_library.util.YdVedio;

import java.lang.ref.WeakReference;

import io.microshow.rxffmpeg.RxFFmpegCommandList;
import io.microshow.rxffmpeg.RxFFmpegInvoke;
import io.microshow.rxffmpeg.RxFFmpegSubscriber;
import io.reactivex.disposables.CompositeDisposable;

public class MainActivity extends AppCompatActivity {
private TextView tv;
private TextView tv1;
private TextView tv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=findViewById(R.id.tv);
        tv1=findViewById(R.id.tv1);
        tv2=findViewById(R.id.tv2);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url="http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
                YdVedio.INSTANCE.playVedio(MainActivity.this,"网络视频",url);
            }
        });
        tv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String source1 = "file://"+ Environment.getExternalStorageDirectory().getPath() + "/zbm/audio/test.amr";
                YdVedio.INSTANCE.playAudio(MainActivity.this,source1);
            }
        });
        tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String inputUrl=Environment.getExternalStorageDirectory().getPath() + "/zbm/download/video/test.mp4";
                String outputUrl=Environment.getExternalStorageDirectory().getPath() + "/zbm/download/video/output.mp4";
                YdVedio.INSTANCE.compressVedio(MainActivity.this,inputUrl,outputUrl).setCompressListener(new CompressListener() {
                    @Override
                    public void compressResult(Boolean result, String outputUrl, String msg) {
                        if(result){
                            Toast.makeText(MainActivity.this,"压缩成功！"+outputUrl,Toast.LENGTH_SHORT).show();
                        }else {
                            Toast.makeText(MainActivity.this,"压缩失败！"+msg,Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });
    }





    @Override
    public void onDestroy() {
        super.onDestroy();
        YdVedio.INSTANCE.compressDestory();
    }



}